#ifndef CBEZIER_H
#define CBEZIER_H

#include <QObject>
#include <QVector>
#include <QPoint>
#include <QThread>

class CBezier : public QObject
{
    Q_OBJECT
public:
    explicit CBezier(QObject *parent = nullptr);

    inline void setBezierOrder(quint8 order)               {    m_order = order;    }

    inline void setBezierPoints(QVector<QPoint> &points)   {    m_origin_points = points;  }

    void bezierFitting();

private:

    void twoOrderBezier();
    void threeOrderBezier();

    void twoOrderBezierRecursion(QPoint p1, QPoint p2, QPoint p3, float t);
    void threeOrderBezierRecursion(QPoint p1, QPoint p2, QPoint p3, QPoint p4, float t);

    int calcBezierX(QPoint, QPoint, float);
    int calcBezierY(QPoint, QPoint, float);

signals:

    void signalSendTwoBezierPoint(QPoint);
    void signalSendThreeBezierPoint(QPoint);

    void signalTwoOrderRollLine(QPoint, QPoint);
    void signalThreeOrderRollLine(QPoint, QPoint, QPoint, QPoint, QPoint, QPoint);
private:

    quint8          m_order;
    QVector<QPoint> m_origin_points;

    QPoint m_start_point;
    QPoint m_key_point;
    QPoint m_end_point;

};

#endif // CBEZIER_H
